<template>
  <div>
    <div class="chunk">
      <a-form :form="form" id="update-form" :hideRequiredMark="true">
        <div class="header">
          <h3>一、报告信息</h3>
          <div class="operate">
            <a-button type="primary" @click="exportExcel">导出报告</a-button>
          </div>
        </div>
        <div class="form-main-content">
          <a-row :gutter="10">
            <a-col :span="6" class="form-item">
              <p>总架次</p>
              <h2>{{tableData.connects}}架次</h2>
            </a-col>
            <a-col :span="6" class="form-item">
              <p>工作总时长</p>
              <h2>{{tableData.duration}}</h2>
            </a-col>
            <a-col :span="6" class="form-item">
              <p>总面积 ( 距离, 点数 )</p>
              <h2>{{tableData.area}}平方公里</h2>
            </a-col>
            <a-col :span="6" class="form-item">
              <p>投入各类设备数</p>
              <h2>{{tableData.device_count}}台</h2>
            </a-col>
          </a-row>
          <a-row :gutter="10">
            <a-col :span="6" class="form-item">
              <p>无人机工作时间</p>
              <h2>{{tableData.plane_worktime}}</h2>
            </a-col>
            <a-col :span="6" class="form-item">
              <p>含标注总计</p>
              <h2>{{tableData.marker_count}}个</h2>
            </a-col>
            <a-col :span="6" class="form-item">
              <p>完成期数</p>
              <h2>{{tableData.finish_period}}</h2>
            </a-col>
            <a-col :span="6" class="form-item">
              <p>未完成期数</p>
              <h2>{{tableData.unfinish_period}}</h2>
            </a-col>
          </a-row>
          <a-row :gutter="10">
            <a-col :span="6" class="form-item">
              <p>标签种类</p>
              <h2>{{tableData.tags}}个</h2>
            </a-col>
          </a-row>
        </div>
      </a-form>
      <div class="relate-service">
        <h3>二、设备使用情况</h3>
        <a-row :gutter="10">
          <a-col :span="24">
            <table border="1" class="label-table">
              <tr>
                <td class="table-title">设备类型</td>
                <td class="table-text">次数</td>
              </tr>
              <tr v-for="(item,index) in tableData.devices" :key="index">
                <td class="table-title">入云龙无人机</td>
                <td class="table-text">72</td>
              </tr>
              <!-- <tr>
                <td class="table-title">入云龙无人机</td>
                <td class="table-text">32</td>
              </tr>
              <tr>
                <td class="table-title">入云龙无人机</td>
                <td class="table-text">42</td>
              </tr>
              <tr>
                <td class="table-title">入云龙无人机</td>
                <td class="table-text">24</td>
              </tr>
              <tr>
                <td class="table-title">入云龙无人机</td>
                <td class="table-text">82</td>
              </tr>
              <tr>
                <td class="table-title">入云龙无人机</td>
                <td class="table-text">29</td>
              </tr>-->
            </table>
          </a-col>
        </a-row>
      </div>
      <div class="relate-service">
        <h3>三、标注分析</h3>
        <a-row :gutter="10">
          <a-col :span="6" class="form-issue">
            <div>
              <h4>常见问题</h4>
              <ul>
                <li v-for="(v,i) in tags" :key="v.id" >
                  <span class="inssue-left">{{i+1}}、{{v.name}} ：</span>
                  <span class="inssue-right">出现次数{{v.id}}次</span>
                </li>
              </ul>
            </div>
          </a-col>
          <a-col :span="18" class="form-issue">
            <div id="analyzeChart"></div>
          </a-col>
        </a-row>
      </div>
    </div>
    <div class="chunk">
      <div class="relate-service">
        <h3>四、标注详情</h3>
        <a-row :gutter="10">
          <a-col :span="24" class="form-issue">
            <div>
              <h4>导出订单统计报告查看所有标注信息</h4>
              <h4>标注样式 :</h4>
            </div>
          </a-col>
          <a-col :span="24">
            <table border="1" class="label-table">
              <tr>
                <td>标题</td>
                <td>{{markers.title}}</td>
              </tr>
              <tr>
                <td>地址</td>
                <td>{{markers.address}}</td>
              </tr>
              <tr>
                <td>坐标</td>
                <td>{{markers.geom}}</td>
              </tr>
              <tr>
                <td>面积</td>
                <td>{{markers.lp_size}}</td>
              </tr>
              <tr>
                <td>标签</td>
                <td>{{markers.title}}</td>
              </tr>
              <tr>
                <td>责任人</td>
                <td>{{markers.operator}}</td>
              </tr>
              <tr>
                <td>备注</td>
                <td>{{markers.letter}}</td>
              </tr>
              <tr>
                <td>标注图片</td>
                <td>
                  <img :src="markers.img" alt />
                </td>
              </tr>
              <tr>
                <td>台账日期</td>
                <td>{{markers.accountime}}</td>
              </tr>
              <tr>
                <td>
                  <span>台账信息</span>
                </td>
                <td>
                  <dl class="table-info">
                    <dt>
                      <img :src="markers.img" alt />
                    </dt>
                    <dd>{{markers.account}}</dd>
                  </dl>
                </td>
              </tr>
            </table>
          </a-col>
        </a-row>
      </div>
    </div>
  </div>
</template>

<script>
import { export_json_to_excel } from "@/utils/Export2Excel";
import { Row, Col, Card, Button, Form } from "ant-design-vue";
export default {
  components: {
    ARow: Row,
    ACol: Col,
    ACard: Card,
    AButton: Button,
    ACardMeta: Card.Meta,
    AForm: Form,
    AFormItem: Form.Item
  },
  data() {
    return {
      form: this.$form.createForm(this),
      data: [],
      tableData: [],
      markers: [],
      tags:[]
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.http("get", `/orders/statistics?id=${this.$route.params.id}`).then(
        res => {
          this.tableData = res.data;
          var str = [];
          for (let k in res.data.markers) {
            str.push(res.data.markers[k]);
          }
          this.markers = str[0];
          this.tags = str[0].tags
          this.myChart(str[0].tags)
        }
      );
      
    },
    exportExcel() {
      const tHeader = [
        "标题",
        "地址",
        "坐标",
        "面积",
        "标签",
        "责任人",
        "备注",
        "标注图片",
        "台账日期",
        "台账信息",
        "台账名称"
      ];

      var date = new Date();
      var data = [
        this.markers.title,
        this.markers.address,
        this.markers.geom,
        this.markers.lp_size,
        this.markers.title,
        this.markers.operator,
        this.markers.letter,
        this.markers.img,
        this.markers.accountime,
        this.markers.img,
        this.markers.account
      ];
      
      data = [data];
      let month = date.getMonth() + 1;
      setTimeout(
        () =>
          export_json_to_excel({
            header: tHeader,
            data,
            filename:
              date.getFullYear() + "-" + month + "-" + date.getDate() + "订单",
            autoWidth: true,
            bookType: "xlsx"
          }),
        300
      );
    },
    myChart(data) {
      var str = {
        name:[],
        value:[]
      }
      data.map(v=>{
        str.name.push(v.name)
        str.value.push(v.id)
      })
      var myChart = this.$echarts.init(document.getElementById("analyzeChart"));
      var myAnalyze = document.getElementById("analyzeChart");
      var option = {
        axisLabel: {
          color: "#fff"
        },
        color: ["#3398DB"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          },
          backgroundColor: "#fff",
          borderRadius: "0px",
          textStyle: {
            fontSize: 16,
            color: "black"
          },
          formatter: "{b} : {c}"
        },
        grid: {
          left: "6%",
          right: "6%",
          bottom: "0%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            name: "标注",
            data: str.name,
            axisTick: {
              alignWithLabel: true
            },
            axisLine: {
              lineStyle: {
                color: "rgb(107, 122, 134)"
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "数量",
            axisLine: {
              lineStyle: {
                color: "rgb(107, 122, 134)"
              }
            },
            splitLine: {
              lineStyle: {
                type: "filament",
                color: "rgb(12, 68, 121)"
              }
            }
          }
        ],
        series: [
          {
            type: "bar",
            barWidth: "43%",
            data: str.value,
            label: {
              normal: {
                show: true,
                position: "top",
                color: "#fff"
              }
            }
          }
        ]
      };
      myChart.setOption(option);
      myAnalyze.children[0].style.width = "100%";
      myAnalyze.children[0].children[0].style.width = "100%";
      window.onresize = function() {
        myChart.resize();
      };
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped >
@import "./../../assets/scss/mixin";
.header {
  @include fj();
  .operate {
    .ant-btn + .ant-btn {
      margin-left: 40px;
    }
  }
}
.form-item {
  p {
    color: rgb(171, 170, 175);
  }
  h2 {
    margin: 7px 0px;
    margin-bottom: 15px;
    font-size: 20px;
  }
}
.img-displayed {
  img + img {
    margin-left: 20px;
  }
}
.form-issue {
  h4 {
    font-size: 15px;
    text-indent: 0.5em;
    margin-bottom: 5px;
    margin-top: 17px;
  }
  ul li {
    text-indent: 1.3em;
    line-height: 30px;
  }
  #analyzeChart {
    width: 100%;
    height: 450px;
  }
}
.chunk {
  #analyzeChartThe {
    width: 100%;
    height: 450px;
  }
  margin-bottom: 10px;
  padding-bottom: 50px;
}
.label-table {
  margin: 10px 0px;
  margin-left: 40px;
  border: 1px solid black;
  font-size: 14px;
  line-height: 35px;
  img {
    width: 220px;
    margin: 20px;
    margin-left: 0;
  }
  tr td:nth-child(1) {
    width: 200px;
    text-align: center;
  }
  tr td:nth-child(2) {
    width: 600px;
    padding-left: 20px;
  }
  .table-info {
    width: 220px;
    text-align: center;
    img {
      margin-bottom: 0;
    }
    margin-bottom: 10px;
  }
  tr:last-child td:nth-child(1) {
    float: left;
    margin-top: 30px;
    border: 0;
  }
  .table-title {
    width: 300px !important;
    margin: 0px !important;
  }
  .table-text {
    width: 380px !important;
    text-align: center !important;
    padding: 0 !important;
  }
}
</style>